package com.tbs.easyhomemoneyserver.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Data
@ApiModel
public class ResultVO <T> implements Serializable {

    public static final long SUCCESS=200,ERROR=400,WARN=500;
    private static final long serialVersionUID = -795000530043039958L;

    @ApiModelProperty("请求返回的数据")
    private T data;
    @ApiModelProperty("请求状态 200成功 400错误 500 警告")
    private long status;
    @ApiModelProperty("附加消息文本")
    private String msg;
    public static  <Y> ResultVO<Y> make(Y data,String msg,long status)
    {
        ResultVO<Y> resultVO=new ResultVO<>();
        resultVO.setMsg(msg);
        resultVO.setData(data);
        resultVO.setStatus(status);
        return resultVO;
    }
    public static  <Y> ResultVO<Y> success(Y data,String msg)
    {
        return make(data,msg,SUCCESS);
    }
    public static  <Y> ResultVO<Y> success(Y data)
    {
        return make(data,"调用成功",SUCCESS);
    }
    public static <Y> ResultVO<Y> error(Throwable throwable)
    {
        return make(null,throwable.getMessage(),ERROR);
    }
}
